package com.example.xinhuaxin.service.impl;

import com.example.xinhuaxin.dao.CardDao;
import com.example.xinhuaxin.dao.PointDao;
import com.example.xinhuaxin.dao.UserDao;
import com.example.xinhuaxin.entity.Card;
import com.example.xinhuaxin.entity.User;
import com.example.xinhuaxin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: YancyZhang
 * @time: 2022/6/2 9:09
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Autowired
    CardDao cardDao;
    @Autowired
    PointDao pointDao;

    @Override
    public User userCheck(String account) {
        return userDao.userCheck(account);
    }

    @Override
    public User login(String account, String pwd){
        User res = userDao.userLogin(account, pwd);
        if(res!=null){
            return res;
        }
        return null;
    }

    public Boolean register(User user){
        pointDao.newPointInfo(user.getUser_id(), 0);
        userDao.register(user);
        return true;
    }

    public User getUserInfo(String user_id){
        return userDao.getUserInfo(user_id);
    }

    @Override
    public List<Card> getUserCardList(String user_id) {
        List<Card> cardList = new ArrayList<>();
        List<Integer> cardIdList = userDao.getUserCardList(user_id);
        cardIdList.forEach(i->cardList.add(cardDao.getCardInfo(i.intValue())));
        System.out.println(cardList);
        return cardList;
    }
}